import request from '@/utils/request'
import { CommonSearch } from '@/config/list'
import { StarTreeNode } from '@/model/common/tree/model'
import { DeptList, DeptBeanData } from '@/model/system/dept/model'

export function loadAllDept () {
  return request<StarTreeNode[]>({
    url: '/starDept/loadAllDept',
    method: 'get'
  })
}

export function loadAllDeptByUnitId (unitId:string, fid:string) {
  return request<StarTreeNode[]>({
    url: `/starDept/loadAllDeptByUnitId?unitId=${unitId}&fid=${fid}`,
    method: 'get'
  })
}

export function loadDeptByFid (data: CommonSearch) {
  return request<DeptList>({
    url: '/starDept/loadDeptByFid',
    data: data,
    method: 'post'
  })
}

export function loadDeptById (id: string) {
  return request<DeptBeanData>({
    url: `/starDept/loadDeptById?id=${id}`,
    method: 'get'
  })
}

export function deleteDept (id: string) {
  return request({
    url: `/starDept/removeDept?id=${id}`,
    method: 'post'
  })
}

export function saveDept (formData: DeptBeanData) {
  return request({
    url: '/starDept/saveDept',
    data: formData,
    method: 'post'
  })
}

export function getMaxIndex (fid: string, unitId:string) {
  return request<string>({
    url: `/starDept/getMaxIndex?fid=${fid}&unitId=${unitId}`
  })
}
